import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    //  购物车数量
    cartTotal: 0,
    userInfo: {
      nickName: "--",
      coin: "0",
      headImg: require("../../assets/img/service.848ec511.png"),
    },
  },
  mutations: {
    //   修改用户信息
    updateUserInfo(state, payload) {
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    initUserInfo(state, payload) {
      state.cartTotal = 0;
      state.userInfo = {
        nickName: "--",
        coin: "0",
        headImg: require("../../assets/img/service.848ec511.png"),
      };
    },
  },
  actions: {
    // 发起请求  得到用户信息,更新到vuex中
    async asyncChangeUserInfo(context) {
      let res2 = await UserProfilesAPI();
      // console.log("UserProfilesAPI", res2);
      context.commit("updateUserInfo", res2.data);
      console.log("更新。。。");
    },
  },
};
